<?php

namespace common\components\behaviors;

use yii\base\Behavior;
use common\models\OmsOrderInfo;
use common\models\OmsOrderStatus;
use common\models\BaseRegion;
use common\models\BaseSite;
use common\models\SysSupplier;
use yii\db\Query;
use common\models\BaseLogisticsInterfaceLog;
use common\models\BaseSupplierGoods;
use common\models\AfterSalesOrders;
use common\models\LogisticsShOrderEditLog;
use common\models\LogisticsShOrderLog;

class AfterSalesOrdersBehavior extends Behavior{
	public function events() {
		return [
			AfterSalesOrders::EVENT_SH_ORDER_EDIT => 'updateShOrderInfo',
		    
		    /***** * 物流接口---售后单操作*/
		];
	}
	
	public function updateShOrderInfo($event) {
                $order = $this->owner;
                $order_type = LogisticsShOrderLog::find()->select('type')->where(['sales_order'=>$order->sales_order])->asArray()->one();
                if ($order_type['type'] == 0) { #售后揽件
                        $time = time(); 
                        $date_time = date("YmdHis",$time);
                        $token = md5(md5($date_time).'5bbfd68e674314de6775c6efb3ee9d02');
                        $type_status = $order->type_status;
                        if (!empty($type_status)) {
                                $type = LogisticsShOrderLog::getShOrderType($type_status);
                        } 
                        $desc = $type.' - '.$order->goods_name.'['.$order->color.']'.' - '.$order->serial_code.' - '.$order->need_content;
                        $orderCode = '51SH-'.$order->sales_order;
                        $content = [
                                'orderCode'=>$orderCode,
                                'desc'=>$desc,
                        ];
                        
                        $content = json_encode($content);
                        $data = [
                                "time" => $date_time,
                                "token" => $token,
                                "content" => $content,
                        ];  
                        $data = json_encode($data); 
                        LogisticsShOrderEditLog::createLogisticsEditOrderLog($order->sales_order,$data);     
                }        
                             
	}
}

?>